package com.linwen.excise.niuke._20;

import java.util.Scanner;
import java.util.regex.Pattern;

/**
 * @author wlw
 * @date 2023/3/3 11:26 PM
 */
public class _20密码验证合格程序 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()){
            String str = scanner.nextLine();
            if(str.length()<8){
                System.out.println("NG");
                continue;
            }
            if(!getMatchCountPattern(str)){
                System.out.println("NG");
                continue;
            }
            if(getString(str,0,3)){
                System.out.println("NG");
                continue;
            }
            System.out.println("OK");

        }
    }

    // 校验是否有重复子串
    private static boolean getString(String str, int l, int r) {
        if (r >= str.length()) {
            return false;
        }
        if (str.substring(r).contains(str.substring(l, r))) {
            return true;
        } else {
            return getString(str,l+1,r+1);
        }
    }

    private static boolean getMatchCountPattern(String str) {
        int count = 0;
        Pattern pattern1 = Pattern.compile("[a-z]");
        if(pattern1.matcher(str).find()){
            count++;
        }
        Pattern pattern2 = Pattern.compile("[A-Z]");
        if(pattern2.matcher(str).find()){
            count++;
        }
        Pattern pattern3 = Pattern.compile("[0-9]");
        if(pattern3.matcher(str).find()){
            count++;
        }
        Pattern pattern4 = Pattern.compile("[^a-zA-Z0-9]");
        if(pattern4.matcher(str).find()){
            count++;
        }
        if(count>=3){
            return true;
        }
        return false;
    }
}
